/*
 * @Description:
 * @Author: 小雨
 * @Date: 2024-06-28 11:26:31
 * @LastEditTime: 2024-06-28 11:26:33
 * @LastEditors: 小雨
 */
const qs = require('querystring');
const bodyParser = (req, res, next) => {
    //定义一个字符串 存储客户端发来的请求体数据
    let str = '';
    //监听req.data事件
    req.on('data', (chunk) => {
        str += chunk;
    });
    //监听req.end事件，请求结束
    req.on('end', () => {
        //请求结束str就是完成的请求体数据
        //把字符串解析为对象格式
        let body = qs.parse(str);
        req.body = body;
    });
    next();
};

module.exports = bodyParser;
